{% extends 'base.html' %}
{% load static %}
{% block title %}输入输出示例{% endblock %}
{% block css %}
<link href="{% static 'login.css' %}" rel="stylesheet" />
<style>
    body {
        font-family: Arial, sans-serif;
        margin: 0;
        padding: 0;
        color: #333;
        background-color: #f0f0f0;
    }

    .container {
        max-width: 800px;
        margin: 60px auto;
        padding: 20px;
        background-color: #fff;
        box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        border-radius: 8px;
    }

    h2 {
        font-size: 24px;
        color: #333;
        margin-bottom: 20px;
        text-align: center;
    }

    .tab {
        overflow: hidden;
        border-bottom: 2px solid #eee;
    }

    .tab button {
        background-color: inherit;
        border: none;
        outline: none;
        cursor: pointer;
        padding: 10px 20px;
        transition: background-color 0.3s;
        font-size: 16px;
    }

    .tab button:hover {
        background-color: #ddd;
    }

    .tab button.active {
        background-color: #0099ff;
        color: white;
    }

    .tab-content {
        display: none;
        padding: 20px 0;
    }

    .tab-content.active {
        display: block;
    }

    label {
        font-weight: bold;
    }

    input[type="text"], textarea, input[type="file"] {
        width: calc(100% - 22px);
        padding: 10px;
        margin: 10px 0;
        border: 1px solid #ddd;
        border-radius: 5px;
        font-size: 16px;
    }

    button[type="submit"] {
        background-color: #0099ff;
        color: #fff;
        padding: 10px 20px;
        border: none;
        border-radius: 4px;
        cursor: pointer;
        font-size: 16px;
        transition: background-color 0.3s;
    }

    button[type="submit"]:hover {
        background-color: #007bff;
    }

    .output-section {
        border-top: 2px solid #eee;
        padding-top: 20px;
    }

    .output-section p {
        background: #f1f1f1;
        padding: 10px;
        border-radius: 5px;
        margin: 10px 0;
        white-space: pre-wrap; /* Preserve whitespace and line breaks */
    }
</style>
{% endblock %}

{% block content %}
<div class="container">
    <div class="input-section">
        <h2>输入</h2>
        <div class="tab">
            <button class="tablinks" onclick="openTab(event, 'TextInput')" id="defaultOpen">文本输入</button>
            <button class="tablinks" onclick="openTab(event, 'FileInput')">文件上传</button>
        </div>

        <form id="inputForm" method="post" enctype="multipart/form-data" action="{% url 'submit' %}">
            {% csrf_token %}
            <div id="TextInput" class="tab-content">
                <label for="textInput">文本输入：</label>
                <textarea id="textInput" name="textInput" rows="5" placeholder="请输入文本"></textarea>
            </div>

            <div id="FileInput" class="tab-content">
                <label for="fileInput">文件上传：</label>
                <input type="file" id="fileInput" name="fileInput">
            </div>

            <button type="submit">提交</button>
        </form>
    </div>

    <div class="output-section">
        <h2>输出</h2>
        <p id="textOutput">文本输出：{{ text_output|linebreaksbr }}</p>
        <p id="fileOutput">文件输出：{{ file_output }}</p>
        <p id="codeOutput">结果输出：{{ code_output|linebreaksbr }}</p>
    </div>
</div>

<script>
    function openTab(evt, tabName) {
        var i, tabcontent, tablinks;
        tabcontent = document.getElementsByClassName("tab-content");
        for (i = 0; i < tabcontent.length; i++) {
            tabcontent[i].style.display = "none";
        }
        tablinks = document.getElementsByClassName("tablinks");
        for (i = 0; i < tablinks.length; i++) {
            tablinks[i].className = tablinks[i].className.replace(" active", "");
        }
        document.getElementById(tabName).style.display = "block";
        evt.currentTarget.className += " active";
    }
    document.addEventListener("DOMContentLoaded", function() {
        document.getElementById("defaultOpen").click();
    });
</script>
{% endblock %}
